﻿package Connect;

import org.json.JSONObject;
import android.os.Message;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
import android.os.Handler;

public class PhoneLogin
{
    public String PhoneNumber;
    public String Password;
    public PhoneLogin(String PhoneNumber,String Password)
    {
        this.PhoneNumber=PhoneNumber;
        this.Password=Password;
    }


    public String senduserphone()
    {
        try {
            ConnectMessage a = new ConnectMessage();
            Socket send = new Socket(a.GetIp(), 8800);
            BufferedReader br = new BufferedReader(new InputStreamReader(send.getInputStream(), "UTF-8"));
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(send.getOutputStream(),"UTF-8"));
            JSONObject Mess=new JSONObject();
            Mess.put("jsonid","1");
            Mess.put("userphonenumber",PhoneNumber);
            Mess.put("userpassword",Password);
            bw.write(Mess.toString());
            String str=null;
            while(true)
            {
                str=br.readLine();
                if(str!=null)
                {
                    break;
                }
            }
            JSONObject object=new JSONObject().getJSONObject(str);
            String status=object.getString("status");
            bw.close();
            br.close();
            send.close();
            return status;
        }catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}
